require('dotenv').config()

const express = require('express')
const expressLayout = require('express-ejs-layouts')

const connectDB = require('./server/config/db')

const app = express()
const port = 3000 || process.env.port

// 连接数据库
connectDB()

// 静态文件
app.use(express.static('public'))

// 模板引擎
app.use(expressLayout)
app.set('layout', './layouts/main')
app.set('view engine', 'ejs')

// 路由处理
app.use('/', require('./server/routes/main'))

app.listen(port, () => {
  console.log(`app listening on port ${port}`)
})
